﻿#include "OperGeometryBool.h"
#include "FITK_Kernel/FITKAppFramework/FITKGlobalData.h"
#include "FITK_Kernel/FITKAppFramework/FITKAppFramework.h"
#include "OperatorsInterface/GraphEventOperator.h"
#include <QWidget>

#include "GUIDialog/GUIGeometryDialog/GUIGeometryBoolDialog.h"

bool ModelOper::OperGeometryBool::execGUI(){
    //获取动作名称
    QString actionName = _emitter->objectName();
    if (actionName == "actionGeometricOperationsUnite")
    {
        this->createBoolUniteOper();
    }
    else if (actionName == "actionGeometricOperationsIntersect")
    {
        this->createBoolIntersectOper();
    }
    else if (actionName == "actionGeometricOperationsSubtract")
    {
        this->createBoolSubtractOper();
    }
    return false;
}

bool ModelOper::OperGeometryBool::execProfession()
{
    //获取此次要建模时候的检查函数的返回值
    bool check_state = false;
    //this->argValue("check_state", check_state);
    //if (check_state==false)
    //{
    //    return false;
    //}
    int objID = -1;
    this->argValue("objID", objID);
    //获取三维可视对象数据-用于渲染数据对象
    EventOper::GraphEventOperator* graphOper = FITKOPERREPO->getOperatorT<EventOper::GraphEventOperator>("GraphPreprocess");
    if (graphOper == nullptr)return false;
    graphOper->updateGraphRecursively(objID, 2, false);
    return true;
}
bool ModelOper::OperGeometryBool::createBoolUniteOper()
{
    //主界面
    QWidget* mw = FITKAPP->getGlobalData()->getMainWindow();
    if (!mw) return false;
    //创建界面
    GUI::GUIGeometryBoolDialog* dialog = new GUI::GUIGeometryBoolDialog(this, Interface::FITKAbsGeoOperBool::GBTAdd, mw);

    //当界面执行完毕后执行
    connect(dialog, &QDialog::accepted, this, &OperGeometryBool::execProfession);
    dialog->show();
    return true;
}

bool ModelOper::OperGeometryBool::createBoolIntersectOper()
{
    //主界面
    QWidget* mw = FITKAPP->getGlobalData()->getMainWindow();
    if (!mw) return false;
    //创建界面
    GUI::GUIGeometryBoolDialog* dialog = new GUI::GUIGeometryBoolDialog(this, Interface::FITKAbsGeoOperBool::GBTCommon, mw);

    //当界面执行完毕后执行
    connect(dialog, &QDialog::accepted, this, &OperGeometryBool::execProfession);
    dialog->show();
    return true;
}
bool ModelOper::OperGeometryBool::createBoolSubtractOper()
{
    //主界面
    QWidget* mw = FITKAPP->getGlobalData()->getMainWindow();
    if (!mw) return false;
    //创建界面
    GUI::GUIGeometryBoolDialog* dialog = new GUI::GUIGeometryBoolDialog(this, Interface::FITKAbsGeoOperBool::GBTCut, mw);

    //当界面执行完毕后执行
    connect(dialog, &QDialog::accepted, this, &OperGeometryBool::execProfession);
    dialog->show();
    return true;
}
